import WxmpRsa from "wxmp-rsa";
//
//公钥和私钥换自己的
// 定义公钥
const publicKey = `
  -----BEGIN PUBLIC KEY-----
  MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCANvSu1G8w7mm8OXbMzjZ5YgzLxH2/87uH+PirHBF08rmXf0L5cBQblqCs9TJiId0fdG0QDm7Oh383DlaVwmDRwNMJ8yN/iud57fBgpQGBnSgEmz/KjhO4k0fndAdEFkmgo6Z8HsRJrgwIDAQAB
  -----END PUBLIC KEY-----
`;
// 定义私钥
const privateKey = `
-----BEGIN CERTIFICATE-----
MIIEJTCCAw2gAwIBAgIUO4sxBbmcDJbE+R2+Hlcvdg0gWDkwDQYJKoZIhvcNAQEL
BQAwXjELMAkGA1UEBhMCQ04xEzARBgNVBAoTClRlbnBheS5jb20xHTAbBgNVBAsT
FFRlbnBheS5jb20gQ0EgQ2VudGVyMRswGQYDVQQDExJUZW5wYXkuY29tIFJvb3Qg
Q0EwHhcNMjQwMzAxMDUxNDU1WhcNMjkwMjI4MDUxNDU1WjB/MRMwEQYDVQQDDAox
NjY5MjIyNjUzMR8wHQYDVQQKDBZXZUNoYXQgTWVyY2hhbnQgU3lzdGVtMScwJQYD
VQQLDB7mna3lt57ppbfpgZPnp5HmioDmnInpmZDlhazlj7gxCzAJBgNVBAYTAkNO
MREwDwYDVQQHDAhTaGVuWmhlbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBAKxpYLIqw/CAD74lZI4Aj7mycQIIiataDtJizl0Y40mAc3tgCRS6EGX1okQ8
YvvLiQuVM/y5RDuTvBo/N53R/WOEBaUYWQrllbbgvQB3y4DyR3IXC3Kx23Ur+1P+
WMfl3yt/vA+UETEb+HITT9dqBSsJ0bGaVn4vjX9LXUfF9MyFotRhRnjutrTJpVtL
wR1Bf1xJfNdBbYJOekjdBOw1DDvtBta6ehAGjDBw8eVlMhkjiXN7ha+Aa4w9VnEf
l5rJoQpbsf+Bpc9yCIS3In4rOGtPS1TR7tegIWfq/Cx6taRQhtGTTzzjC7PhE06m
FLL0HPbKE+Cwgkoi3LVbvc4+H08CAwEAAaOBuTCBtjAJBgNVHRMEAjAAMAsGA1Ud
DwQEAwID+DCBmwYDVR0fBIGTMIGQMIGNoIGKoIGHhoGEaHR0cDovL2V2Y2EuaXRy
dXMuY29tLmNuL3B1YmxpYy9pdHJ1c2NybD9DQT0xQkQ0MjIwRTUwREJDMDRCMDZB
RDM5NzU0OTg0NkMwMUMzRThFQkQyJnNnPUhBQ0M0NzFCNjU0MjJFMTJCMjdBOUQz
M0E4N0FEMUNERjU5MjZFMTQwMzcxMA0GCSqGSIb3DQEBCwUAA4IBAQBDQ4W+Td1F
7ohRIudLYdHclm+esQq1wxF/sJzofelsqCTAa6yxsm9nrxdGRX4cYQIM/u8+KQmr
k+jv+bVWq4WKSnWWn5hQEQf3kg7owL4PUKdQNPubzbvYEHyhmBRXdPEdknVHDbgM
OFkriadnOZWx0An0u+PHqcK4ML8gFhj/V1V1Lbe6uUMPp+mOaf8dTa2NEsM1P/8p
crv/R4ObTeGVaRC43kSVV75tx2/D/WQcG4le272jiljnAPbB2zcH/zIHfI0xdGi0
b7QkQa2DffA8PfQ9/TJWKz/gMxAO3+ppre/qM+2QUDGr4I6FKkHyBPMlgHtXFzk6
o2XI7Yb1QAI6
-----END CERTIFICATE-----
`;

//加密
function getRsaCode(str) {
  console.log("🚀 ~ getRsaCode ~ str:", str);
  const rsa = new WxmpRsa();
  rsa.setPublicKey(privateKey);
  const data = rsa.encryptLong(str);
  return data;
}

//解密
function getRsaDeCode(str) {
  const rsa = new WxmpRsa();
  rsa.setPrivateKey(privateKey);
  const data = rsa.decryptLong(str);
  return data;
}

export default {
  getRsaCode,
  getRsaDeCode,
};
